﻿using IListNode;
using System;
using System.ComponentModel;

namespace _226_invert_binary_tree
{
    class Program
    {
        static void Main (string[] args)
        {
            TreeNode root = new TreeNode (4);
            TreeNode nodel = new TreeNode (2);
            TreeNode noder = new TreeNode (7);
            nodel.left = new TreeNode (1);
            nodel.right = new TreeNode (3);
            noder.left = new TreeNode (6);
            noder.right = new TreeNode (9);
            root.left = nodel;
            root.right = noder;

            Solution a = new Solution ();

            TreeNode node = a.InvertTree (root);
            Console.WriteLine ();
        } 
    }

    public class Solution
    {
        public TreeNode InvertTree (TreeNode root)
        {
            if (root == null) return root;

            TreeNode node = root.left;
            root.left = root.right;
            root.right = node;

            InvertTree (root.left);
            InvertTree (root.right);

            return root;
        }

    }
}
